using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace DataLayerTest.Models.Mapping
{
    public class MessageMap : EntityTypeConfiguration<Message>
    {
        public MessageMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Subject)
                .HasMaxLength(255);

            // Table & Column Mappings
            this.ToTable("Message");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.IdSender).HasColumnName("IdSender");
            this.Property(t => t.IdReceiver).HasColumnName("IdReceiver");
            this.Property(t => t.DateTime).HasColumnName("DateTime");
            this.Property(t => t.Subject).HasColumnName("Subject");
            this.Property(t => t.Content).HasColumnName("Content");
            this.Property(t => t.IsRead).HasColumnName("IsRead");

            // Relationships
            this.HasRequired(t => t.User)
                .WithMany(t => t.Messages)
                .HasForeignKey(d => d.IdReceiver);
            this.HasRequired(t => t.User1)
                .WithMany(t => t.Messages1)
                .HasForeignKey(d => d.IdSender);

        }
    }
}
